package com.itcast.springboot.waste_recovery.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itcast.springboot.waste_recovery.domain.WasteClassification;
import com.itcast.springboot.waste_recovery.domain.WasteData;
import com.itcast.springboot.waste_recovery.mapper.WasteClassificationMapper;
import com.itcast.springboot.waste_recovery.mapper.WasteDataMapper;
import com.itcast.springboot.waste_recovery.service.WasteClassificationService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 垃圾分类表 服务实现类
 * </p>
 *
 * @author 小破烂
 * @since 2020-08-19
 */
@Service
public class WasteClassificationServiceImpl extends ServiceImpl<WasteClassificationMapper, WasteClassification> implements WasteClassificationService {
    @Resource
    WasteClassificationMapper wasteClassificationMapper;

    @Resource
    WasteDataMapper wasteDataMapper;

    @Override
    public Map<String, Object> getWasteClassifications() {
        List<WasteClassification> wasteClassifications = wasteClassificationMapper.selectList(null);

        //获取第一个分类包含的废品名
        QueryWrapper<WasteData> wasteDataWrapper = new QueryWrapper<>();
        wasteDataWrapper.eq("classification_id", 1);
        List<WasteData> firseWasteDatas = wasteDataMapper.selectList(wasteDataWrapper);

        HashMap<String, Object> map = new HashMap<>();
        map.put("wasteClassifications", wasteClassifications);
        map.put("firseWasteDatas", firseWasteDatas);

        return map;
    }
}
